package com.xxx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.pojo.LoginUser;
import com.xxx.pojo.UserOperate;
import com.xxx.mapper.UserOperateMapper;
import com.xxx.service.UserOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserOperateServiceImpl extends ServiceImpl<UserOperateMapper, UserOperate> implements UserOperateService {

    @Override
    public void addLogManage(String module, String content, String operate) {
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        boolean save = super.save(new UserOperate(null, loginUser.getUser().getUserId(), module, content, operate, loginUser.getUser().getName(), loginUser.getDepartment(), LocalDateTime.now(), "", null, null));
        if (save){
            return ;
        }else {
            throw new RuntimeException("日志操作异常!");
        }
    }
}
